package com.wva.video.config;


import com.wva.video.enums.QueueEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: hong
 * @Date: 2025/2/3 23:14:37
 */
@Configuration
public class MQConfig {

    //预处理队列
    @Bean
    FanoutExchange videoPreProcessFanout() {
        return new FanoutExchange(QueueEnum.VIDEO_PROCESS_PRE.getExchange());
    }
    @Bean
    Queue videoPreProcessQueue() {
        return new Queue(QueueEnum.VIDEO_PROCESS_PRE.getQueue());
    }
    @Bean
    Binding videoPreProcessBinding(Queue videoPreProcessQueue, FanoutExchange videoPreProcessFanout) {
        return BindingBuilder
                .bind(videoPreProcessQueue)
                .to(videoPreProcessFanout);
    }


    //主要处理队列
    @Bean
    FanoutExchange videoMainProcessFanout() {
        return new FanoutExchange(QueueEnum.VIDEO_PROCESS_MAIN.getExchange());
    }
    @Bean
    Queue videoMainProcessQueue() {
        return new Queue(QueueEnum.VIDEO_PROCESS_MAIN.getQueue());
    }
    @Bean
    Binding videoMainProcessBinding(Queue videoMainProcessQueue, FanoutExchange videoMainProcessFanout) {
        return BindingBuilder
                .bind(videoMainProcessQueue)
                .to(videoMainProcessFanout);
    }


    //机器审核队列
    @Bean
    FanoutExchange videoMachineCensorFanout() {
        return new FanoutExchange(QueueEnum.VIDEO_PROCESS_MACHINE_CENSOR.getExchange());
    }
    @Bean
    Queue videoMachineCensorQueue() {
        return new Queue(QueueEnum.VIDEO_PROCESS_MACHINE_CENSOR.getQueue());
    }
    @Bean
    Binding videoMachineCensorBinding(Queue videoMachineCensorQueue, FanoutExchange videoMachineCensorFanout) {
        return BindingBuilder
                .bind(videoMachineCensorQueue)
                .to(videoMachineCensorFanout);
    }


    /**
     * canal topic交换机
     * @return
     */
    @Bean
    TopicExchange canalTopic() {
        return new TopicExchange(QueueEnum.VIDEO_CHANGE.getExchange());
    }
    @Bean
    Queue videoChangeQueue() {
        return new Queue(QueueEnum.VIDEO_CHANGE.getQueue());
    }
    @Bean
    Queue userChangeQueue() {
        return new Queue(QueueEnum.USER_CHANGE.getQueue());
    }
    @Bean
    Queue videoMetadataChangeQueue() {
        return new Queue(QueueEnum.VIDEO_META_CHANGE.getQueue());
    }
    @Bean
    Binding videoChangeBinding(Queue videoChangeQueue, TopicExchange canalTopic) {
        return BindingBuilder
                .bind(videoChangeQueue)
                .to(canalTopic)
                .with(QueueEnum.VIDEO_CHANGE.getRoutingKey());
    }
    @Bean
    Binding videoMetadataChangeBinding(Queue videoMetadataChangeQueue, TopicExchange canalTopic) {
        return BindingBuilder
                .bind(videoMetadataChangeQueue)
                .to(canalTopic)
                .with(QueueEnum.VIDEO_META_CHANGE.getRoutingKey());
    }
    @Bean
    Binding userChangeBinding(Queue userChangeQueue, TopicExchange canalTopic) {
        return BindingBuilder
                .bind(userChangeQueue)
                .to(canalTopic)
                .with(QueueEnum.USER_CHANGE.getRoutingKey());
    }



    //互动行为日志队列
    @Bean
    TopicExchange interactionLogTopic() {
        return new TopicExchange(QueueEnum.INTERACTION_LOG_1.getExchange());
    }
    @Bean
    Queue interactionLogQueue1() {
        return new Queue(QueueEnum.INTERACTION_LOG_1.getQueue());
    }
    @Bean
    Binding interactionLogQueue1Binding(Queue interactionLogQueue1, TopicExchange interactionLogTopic) {
        return BindingBuilder
                .bind(interactionLogQueue1)
                .to(interactionLogTopic)
                .with(QueueEnum.INTERACTION_LOG_1.getRoutingKey());
    }

}
